﻿using System;
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using InventoryManagement;
using System.Data;

namespace MII_FIF.Layouts.MII_FIF.ChangeRequest
{
    public partial class ViewCRVMWare : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Generic.IsUserInGroup(Configuration.ChangeRequestGroupName))
            {
                btnAdd.Click += btnAdd_Click;
                gridCRVMWare.RowCommand += gridCRVMWare_RowCommand;
                gridCRVMWare.PageIndexChanging += gridCRVMWare_PageIndexChanging;
                //((Label)Header.FindControl("lblHeader")).Text = "View Change Request VM Ware";
                if (!IsPostBack)
                {
                    load();
                }
            }
            else
            {
                Response.Redirect(Generic.GenLink("/"));
            }
        }

        void gridCRVMWare_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridCRVMWare.DataSource = (DataTable)ViewState["CR"];
            gridCRVMWare.PageIndex = e.NewPageIndex;
            gridCRVMWare.DataBind();
        }

        void gridCRVMWare_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "view")
            {
                Response.Redirect(Generic.GenLink("/_Layouts/MII_FIF/ChangeRequest/CRVMWare.aspx?ID="+e.CommandArgument));
            }
        }

        void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect(Generic.GenLink("/_Layouts/MII_FIF/ChangeRequest/CRVMWare.aspx"));
        }

        void load()
        {
            CR_VM CR = new CR_VM();
            ViewState["CR"] = CR.SelectByParam();

            //DataTable DT = (DataTable)ViewState["CR"];

            //if (DT.Rows.Count > 0)
            //{
            //    DT.Columns.Add("LabelName",typeof(string));
            //    foreach (DataRow dr in DT.Rows)
            //    {
            //        InventoryManagement.Inventory_VM VM = new InventoryManagement.Inventory_VM();
            //        VM.ID = Guid.Parse(dr["ID_VM"].ToString());
            //        VM.Select();

            //        InventoryManagement.Inventory_Physical phy = new Inventory_Physical();
            //        phy.ID = VM.ID_LabelName;
            //        phy.Select();
            //        dr["LabelName"] = phy.LabelName;
            //    }
            //}

            //ViewState["CR"] = DT;
            gridCRVMWare.DataSource = (DataTable)ViewState["CR"];
            gridCRVMWare.DataBind();
        }
    }
}
